#include "SComboBox.h"
#include <QColor>
#include <QHBoxLayout>
#include <core/StyleMgr.h>
#include <QAbstractItemView>
#include <QListView>

SComboBox::SComboBox(QWidget* parent /*= nullptr*/) 
	: QComboBox(parent)
{
	setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	
	QWidget* container = static_cast<QWidget*>(view()->parent());
	container->setAttribute(Qt::WA_TranslucentBackground);
	container->setWindowFlag(Qt::FramelessWindowHint);
	container->setWindowFlag(Qt::NoDropShadowWindowHint);

	QString m_styleSheet = QString(
		"QComboBox						{color:#%1; padding: 4px 5px 4px 8px; border-radius:2px;border:1px solid #%3; background-color:#%2;}"
		"QComboBox:hover				{background-color:#%5;}"
		"QComboBox:on					{color:#%4;border:1px solid #%4;background-color:#%2;border-radius:2px;}"
		"QComboBox::drop-down			{subcontrol-origin:padding;subcontrol-position:top right; border-radius:2px; width:20px;}"
		"QComboBox::down-arrow:on		{border-image:url(:/widgets/image/dropdown_up/dropdown_up_normal.png);}"
		"QComboBox::down-arrow			{border-image:url(:/widgets/image/dropdown_down/dropdown_down_normal.png);}"
		"QComboBox QAbstractItemView	{outline:0px;border:1px solid #%3; background-color:#%2;border-radius:2px;margin-top:6px;}"
		"QComboBox QAbstractItemView::item			{padding-left:4px;color:#%1;height:24px;background-color:#%2;}"
		"QComboBox QAbstractItemView::item:hover	{background-color:#%5;}"
		"QComboBox QAbstractItemView::item:selected	{color:#%4;background-image:url(:/widgets/image/dropdown_check/dropdown_check_pressed.png);background-origin:content;background-repeat:no-repeat;background-position:right;}"
	)
		.arg(StyleMgr::instance().color("TextNormal").rgb(), 0, 16)
		.arg(StyleMgr::instance().color("BackNormal").rgb(), 0, 16)
		.arg(StyleMgr::instance().color("BorderNormal").rgb(), 0, 16)
		.arg(StyleMgr::instance().color("Highlight").rgb(), 0, 16)
		.arg(StyleMgr::instance().color("Hover").rgb(), 0, 16);

	setStyleSheet(m_styleSheet);
	setView(new QListView());

	view()->setSelectionMode(QAbstractItemView::NoSelection);
}

SComboBox::~SComboBox()
{

}